package com.petmall.mapper;

import java.util.List;
import com.petmall.entity.Review;
import org.apache.ibatis.annotations.*;
import com.petmall.entity.Item;

/**
 * Created by pig2guang on 2017/4/3.
 */
@Mapper
public interface ItemMapper {

    @Select("select * from tb_item where status = #{status}")
    public List<Item> selectItemByStatus(int status);

    @Select("select * from tb_item where item_id = #{item_id}")
    public Item selectItemById(long item_id);

    @Select("select * from tb_item_review where item_id = #{item_id} order by time desc")
    public List<Review> selectItemReviewById(long item_id);

    @Select("select * from tb_item_review where order_item_id = #{order_item_id}")
    public Review selectItemReviewByOrderItemId(long order_item_id);

    @Select("select * from tb_item where category = #{category} and status = #{status}")
    public List<Item> selectItemByCategory(@Param("category") int category, @Param("status") int status);

    @Select("select name from tb_item_category where id = #{id}")
    public String selectItemCategoryNameById(int id);

    @Update("update tb_item set num = num + #{num} where item_id = #{item_id}")
    public void updateItemNum(@Param("item_id") long item_id, @Param("num") int num);

    @Update("update tb_item set sales = sales + #{num} where item_id = #{item_id}")
    public void updateItemSales(@Param("item_id") long item_id, @Param("num") int num);

    @Insert("insert into tb_item(category,name,title,description,price,status,num,sales,image,release_time) values(#{category},#{name},#{title},#{description},#{price},#{status},#{num},#{sales},#{image},#{release_time})")
    public void insertItem(@Param("category") int category, @Param("name") String name, @Param("title") String title, @Param("description") String description, @Param("price") Double price, @Param("status") int status, @Param("num") int num, @Param("sales") int sales, @Param("image") String image, @Param("release_time") String release_time);

    @Update("update tb_item set num=#{num},category=#{category},name=#{name},title = #{title},description=#{description},price=#{price} where item_id = #{item_id}")
    public void updateItemInfo(@Param("item_id") long item_id, @Param("category") int category, @Param("name") String name, @Param("title") String title, @Param("description") String description, @Param("price") Double price, @Param("num") int num);

    @Insert("insert into tb_item_review(user_id,order_item_id,item_id,status,score,detail,time) values(#{user_id},#{order_item_id},#{item_id},#{status},#{score},#{detail},#{time})")
    public void insertReview(@Param("user_id") long user_id, @Param("order_item_id") long order_item_id, @Param("item_id") long item_id, @Param("status") int status, @Param("score") int score, @Param("detail") String detail, @Param("time") String time);


}
